import request from '@/utils/request'

//1.获取一级列表分类
//返回值每一项
export interface reqCategoryReturnItemType {
    id: number,
    name: string,
    category1Id?: number,
    category2Id?: number
}
//返回值类型
export type reqCategoryReturnType = reqCategoryReturnItemType[]
//请求一级分类列表
export const requestCategoryList1 = () => {
    return request.get<any, reqCategoryReturnType>("/admin/product/getCategory1")
}

//2.获取二级列表分类
export const requestCategoryList2 = (category1Id: number) => {
    return request.get<any, reqCategoryReturnType>(`/admin/product/getCategory2/${category1Id}`)
}

//3.获取三级列表分类
export const requestCategoryList3 = (category2Id: number) => {
    return request.get<any, reqCategoryReturnType>(`/admin/product/getCategory3/${category2Id}`)
}


//4.获取品牌属性信息
//返回值中attrValueList的每一项类型
export interface reqAttrReturnAttrValueItemType {
    id?: number,
    valueName: string,
    attrId: number,
    isEdit?: boolean
}
//返回值attrValueList类型
export type reqAttrReturnAttrValueType = reqAttrReturnAttrValueItemType[]
//返回值每一项类型
export interface reqAttrReturnItemType {
    id?: number,
    attrName: string,
    categoryId: number,
    categoryLevel: number,
    attrValueList: reqAttrReturnAttrValueType
}
//返回值类型
export type reqAttrReturnType = reqAttrReturnItemType[]
//获取品牌属性
export const requestAttrInfo = (category1Id: number, category2Id: number, category3Id: number) => {
    return request.get<any,reqAttrReturnType>(`/admin/product/attrInfoList/${category1Id}/${category2Id}/${category3Id}`)
}

//5.修改或添加属性
export const requestUpdateOrAddAttr = (attrInfo: reqAttrReturnItemType) => {
    return request.post<any,null>('/admin/product/saveAttrInfo',attrInfo)
}

//6.删除属性
export const requestDeleteAttr = (attrId: number) => {
    return request.delete<any,null>(`/admin/product/deleteAttr/${attrId}`)
}